﻿using UnityEngine;
using System.Collections.Generic;
using Dict.DataModel;
using Dict;

namespace UI
{

    public class UILevelData
    {
        #region dict
        public string level_id;
        public string level_id_number;
        public string level_name;
        public int level_seq;
        public string level_small_icon;
        public string level_big_icon;
        public string chapterId;
        public string level_run_map;//跑图地图

        public int level_reset_cost_ruby;//重置cost砖石
        public string level_drop_show;//掉落显示
        public string level_passed_award;//通关宝箱奖励
        public int level_max_challenge;//最大挑战次数
        public int level_power_cost;

        public int level_camera_angle;
        public float level_camera_height;
        public float level_camera_depth;
        public string level_minimap;
        public int level_player_face_to;

        public Vector3 level_player_born;
        public int level_dict_star=5;
        public string level_open_id;//开放任务ID
        #endregion

        public int level_curr_challenge=0;//当前挑战次数
        public int level_inst_star=0;

        public bool level_inst_open=false;

        public List<UITaskData> level_tasks = new List<UITaskData>();


        public UILevelData( TableCopyMission level )
        {
            this.level_dict_star = 5;
            this.level_id = level.MissionId;
            this.level_name = TableTextBlo.GetText(level.MissionName);
            this.level_big_icon = level.BigIcon;
            this.level_small_icon = level.SmallIcon;
            this.level_run_map =  level.SceneName;
            this.level_drop_show = level.DropShow;
            this.level_camera_angle = (int)level.CameraAngle;
            
            this.level_minimap = Dict.Blo.TableSceneBlo.GetSceneById(level.SceneName).minimapRes;
            
            this.level_player_born = new Vector3( (float)level.BornX, 0, (float)level.BornZ );
            this.level_max_challenge = level.ChallengeCount;
            this.level_power_cost = level.PowerCost;
            this.level_curr_challenge = 0;
            this.level_open_id = level.OpenId;
            this.chapterId = level.ChapterId;

            if( level_id.Contains( "_" ) )
            {
                string[] s= level_id.Split( new char[1] { '_' }, System.StringSplitOptions.RemoveEmptyEntries );
                this.level_id_number = s[s.Length-1];
            }
            else
            {
                this.level_id_number = level_id;
            }

            var tasks = Dict.Blo.DictCopyTaskBlo.GetTasksByLevelId(level_id);

            foreach( var task in tasks )
            {
                level_tasks.Add( new UITaskData( task ) );
            }

            level_tasks.Sort( ( lh, rh ) =>
            {
                var lh_seq = int.Parse( lh.task_id_number );
                var rh_seq = int.Parse( rh.task_id_number );

                if( lh_seq > rh_seq ) return 1; return -1;
            } );
            int i=0;
            foreach( var task in level_tasks )
            {
                task.task_seq = ++i;
            }
        }

        public void Copy( UILevelData data )
        {
            this.level_id = data.level_id;
            this.level_name = data.level_name;
            this.level_big_icon = data.level_big_icon;
            this.level_small_icon = data.level_small_icon;
            this.level_reset_cost_ruby = data.level_reset_cost_ruby;
            this.level_run_map =  data.level_run_map;
            this.level_drop_show = data.level_drop_show;
            this.level_camera_angle = data.level_camera_angle;
            this.level_player_born = new Vector3( data.level_player_born.x, data.level_player_born.y, data.level_player_born.z );
            this.level_max_challenge = data.level_max_challenge;
            this.level_power_cost = data.level_power_cost;
            this.level_seq = data.level_seq;
            this.level_tasks.Clear();
            this.level_tasks.AddRange( data.level_tasks );
            this.level_dict_star = 5;
            this.level_id_number = data.level_id_number;
            this.level_curr_challenge = data.level_curr_challenge;
            this.level_inst_open = data.level_inst_open;
            this.level_open_id = data.level_open_id;
            
            this.level_minimap = data.level_minimap;
        }
    }
}
